package com.example.demo.auth;

import com.example.demo.Redis.RedisUtil;
import com.example.demo.common.RedisConstants;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.Set;

@Service
public class PolicySetService {

    @Resource
    private RedisUtil redisUtil;

    public void PolicySet(String serviceName,String subject,int trust){

        Set subSet = (Set) redisUtil.hget(RedisConstants.policy_prefix+serviceName,RedisConstants.subject);
        if(null == subSet){
            subSet = new HashSet();
        }

        if(!subSet.contains(subject) && null!=subject){
            subSet.add(subject);
            redisUtil.hset(RedisConstants.policy_prefix+serviceName,RedisConstants.subject,subSet);
        }

        redisUtil.hset(RedisConstants.policy_prefix+serviceName,RedisConstants.trust,trust);
    }

}

